home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / ScriptX / Code Samples / anlogclk / loadme.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  5.5 KB  |  145 lines  |  [TEXT/ttxt]

  1. --<<<-
  2. --*******************************************************************************
  3. --*          Demo for:    AnalogClock
  4. --*    Required files: reqFiles/rot8shp.sx
  5. --*                    anlogclk.sx
  6. --*            Author:    Su Quek - Kaleida Labs, Inc.
  7. --*-----------------------------------------------------------------------------*
  8. --*       Description: This script demonstrates how to create an analog clock.
  9. --*                    When you run "anlogclk.sxt", you should see a window
  10. --*                    with analog time display.
  11. --*******************************************************************************
  12.  
  13. module AnalogClockModule
  14.     uses ScriptX
  15. end
  16.  
  17. in module AnalogClockModule
  18.  
  19. --*=============================================================================*
  20. --* Set up DirReps
  21. --*=============================================================================*
  22. global demoDir := theScriptDir
  23. global mediaDir := spawn theScriptDir "media"
  24. global reqFilesDir := spawn theScriptDir "reqfiles"
  25.  
  26. --*=============================================================================*
  27. --* Load required files
  28. --*=============================================================================*
  29. -- Load Rotating Shape
  30. fileIn reqFilesDir name:"rot8shp.sx"
  31.  
  32. -- Load Analog Clock
  33. fileIn demoDir name:"anlogclk.sx"
  34.  
  35.  
  36. --*=============================================================================*
  37. --*    Define Demo 
  38. --*=============================================================================*
  39. class Demo (Window)
  40. end
  41.  
  42. --*=============================================================================*
  43. --*       Method name:    importBitmap
  44. --*             Class:    Demo
  45. --*             Usage: importBitmap self mediaDir bitmapFile
  46. --*                        mediaDir    - DirRep
  47. --*                        bitmapFile  - String object
  48. --*-----------------------------------------------------------------------------*
  49. --*       Description: Imports the given bitmap from the given directory.
  50. --*=============================================================================*
  51. method importBitmap self {class Demo} mediaDir bitmapFile ->
  52. (
  53.     local theStream := getStream mediaDir bitmapFile @readable
  54.     local theColormap := importMedia theImportExportEngine theStream @image @dib @colormap 
  55.     local theBMP := importMedia theImportExportEngine theStream @image @dib @bitmap \
  56.                         colormap:theColormap
  57.     return theBMP
  58. )
  59.  
  60. --*=============================================================================*
  61. --*       Method name:    init
  62. --*             Class:    Demo
  63. --*             Usage: init self 
  64. --*-----------------------------------------------------------------------------*
  65. --*       Description: Creates a 150x150 window.
  66. --*=============================================================================*
  67. method init self {class Demo} #rest args ->
  68. (
  69.     apply nextMethod self boundary:(new Rect x2:150 y2:150) \
  70.                           centered:true \
  71.                           fill:blackBrush \
  72.                           name:"Analog Clock" args
  73.     return self
  74. )
  75.  
  76. --*=============================================================================*
  77. --*       Method name:    afterInit
  78. --*             Class:    Demo
  79. --*             Usage: afterInit self 
  80. --*-----------------------------------------------------------------------------*
  81. --*       Description: Creates the analog clock.
  82. --*=============================================================================*
  83. method afterInit self {class Demo} #rest args ->
  84. (                          
  85.     --*=========================================================================*
  86.     --* Import and create all required bitmaps
  87.     --*=========================================================================*
  88.     local clockFaceBitmap := (importBitmap self mediaDir "clkface.bmp")
  89.     local hourHandBitmap := (importBitmap self mediaDir "hourhand.bmp")
  90.     hourHandBitmap.invisibleColor := whiteColor
  91.     local minHandBitmap := (importBitmap self mediaDir "minhand.bmp")
  92.     minHandBitmap.invisibleColor := whiteColor
  93.  
  94.     --*=========================================================================*
  95.     --* Create an analog clock
  96.     --*=========================================================================*
  97.     local ac := new AnalogClock radius: (ceiling (clockFaceBitmap.bbox.width/2)) \
  98.                                 clockFace: clockFaceBitmap \
  99.                                 hourHand: hourHandBitmap \
  100.                                 minHand: minHandBitmap \
  101.                                 hourAxis: (new Point x:3 y:37) \
  102.                                 minAxis: (new Point x:4 y:57) 
  103.                                                                 
  104.     --*=========================================================================*
  105.     --* Add analog clock to the demo window and display it.
  106.     --*=========================================================================*
  107.     prepend self ac
  108.     show self
  109.     
  110.     return self
  111. )
  112.  
  113. --*=============================================================================*
  114. --*    Create a title container
  115. --*=============================================================================*
  116. object tc (TitleContainer)
  117.     dir        : theScriptDir
  118.     path    : "anlogclk.sxt" 
  119.     name    : "Analog Clock"
  120. end        
  121.     
  122. --*=============================================================================*
  123. --*    Create demo
  124. --*=============================================================================*
  125. object win (Demo)
  126.     title:tc
  127. end
  128.  
  129. --*=============================================================================*
  130. --*    Undefine global DirReps
  131. --*=============================================================================*
  132. demoDir := undefined
  133. mediaDir := undefined
  134. reqFilesDir := undefined
  135.  
  136. --*=============================================================================*
  137. --*    Store module in the title container
  138. --*=============================================================================*
  139. append tc (getModule @AnalogClockModule)
  140. tc.startUpAction := (tc ->    load tc[1]
  141.                             startClock win[1]
  142.                             show win)
  143. close tc
  144. -->>>
  145.